package IO;


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author wuhan
 * @date 2019/10/9 16:10
 */
public class Demo3 {
    public static void main(String[] args) throws IOException {
//        FileReader fr=new FileReader("demo.txt");
////        int ch = fr.read();
////        System.out.println("ch="+(char)ch);
////        while (true){
////            int c=fr.read();
////            if (c==-1){
////                break;
////            }
////            System.out.println((char) c);
////        }
//        char[] ch=new char[100];
//        int num=fr.read(ch);
//        System.out.println("num="+num+"---"+new String(ch));
        Copy();

    }
    public static void Copy(){
        FileWriter fw=null;
        FileReader fd=null;
        char[] buf=new char[1024];
        try {
            fw=new FileWriter("Paste.txt");
            fd=new FileReader("demo.txt");
            int len=0;
            while ( (len=fd.read(buf))!=-1 ){
                fw.write(buf,0,len);
            }
            fw.flush();
        } catch (IOException e) {
            throw new RuntimeException("读写失败");
        }
        finally {
            try {
                assert fd != null;
                fd.close();
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
